| Conditions | 6 |
| Paths | 25 |
| Total Lines | 104 |
| Code Lines | 62 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | function refresh_opener(url) { |
||
| 58 | $(document).ready(function() { |
||
| 59 | var title = document.title, |
||
| 60 | buttons = []; |
||
| 61 | |||
| 62 | if ( typeof window.parent.$ !== "undefined" |
||
| 63 | && window.parent.$('#midcom-dialog').length > 0 ) { |
||
| 64 | var dialog = window.parent.$('#midcom-dialog'); |
||
| 65 | dialog.dialog('option', 'title', title); |
||
| 66 | |||
| 67 | $('body').on('submit', '.midcom-dialog-delete-form', function(e) { |
||
| 68 | e.preventDefault(); |
||
| 69 | var form = $(this).detach().appendTo(dialog); |
||
| 70 | |||
| 71 | form.find('input[name="referrer"]') |
||
| 72 | .val(window.parent.location.href); |
||
| 73 | |||
| 74 | //somehow, the original submit button breaks when detaching |
||
| 75 | form.append($('<input type="hidden" name="' + form.find('input[type="submit"]').attr('name') + '" value="x">')) |
||
| 76 | .submit(); |
||
| 77 | }); |
||
| 78 | |||
| 79 | $(window).on('unload', function() { |
||
| 80 | dialog.nextAll('.ui-dialog-buttonpane').find('button') |
||
| 81 | .prop('disabled', true) |
||
| 82 | .addClass('ui-state-disabled'); |
||
| 83 | }); |
||
| 84 | |||
| 85 | if ($('.midcom-view-toolbar li').length > 0) { |
||
| 86 | $('.midcom-view-toolbar li').each(function() { |
||
| 87 | var btn = $(this).find('a'), |
||
| 88 | options = { |
||
| 89 | click: function() { |
||
| 90 | btn.get(0).click(); |
||
| 91 | btn.addClass('active'); |
||
| 92 | } |
||
| 93 | }; |
||
| 94 | |||
| 95 | add_dialog_button(btn.attr('href'), btn.text(), options); |
||
| 96 | }); |
||
| 97 | } |
||
| 98 | |||
| 99 | if ($('.datamanager2 .form_toolbar > *').length > 0) { |
||
| 100 | $('.datamanager2 .form_toolbar > *').each(function() { |
||
| 101 | var btn = $(this); |
||
| 102 | buttons.push({ |
||
| 103 | text: btn.val() || btn.text(), |
||
| 104 | click: function() { |
||
| 105 | if (btn.hasClass('cancel')) { |
||
| 106 | dialog.dialog('close'); |
||
| 107 | } else { |
||
| 108 | btn.click(); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | }); |
||
| 112 | }); |
||
| 113 | $('.datamanager2 .form_toolbar').hide(); |
||
| 114 | } |
||
| 115 | if (extra_buttons.length > 0) { |
||
| 116 | buttons = extra_buttons.concat(buttons); |
||
| 117 | } |
||
| 118 | |||
| 119 | // This doesn't work under certain circumstances when flexbox is used somewhere in the page: |
||
| 120 | // dialog.dialog('option', 'buttons', buttons); |
||
| 121 | // @todo: The root of the problem seems to be that jquery can't set the content element |
||
| 122 | // to a height of 0, so at some point this could be filed as a bug against their repo. Latest |
||
| 123 | // stable (3.4.1) is affected. For now, we just copy the relevant part from jqueryui's |
||
| 124 | // _createButtons method.. |
||
| 125 | |||
| 126 | var buttonset = dialog.nextAll('.ui-dialog-buttonpane').find('.ui-dialog-buttonset').empty(); |
||
| 127 | |||
| 128 | $.each(buttons, function (name, props) { |
||
| 129 | var click, buttonOptions; |
||
| 130 | props = $.isFunction(props) ? {click: props, text: name} : props; |
||
| 131 | |||
| 132 | // Default to a non-submitting button |
||
| 133 | props = $.extend({type: "button"}, props); |
||
| 134 | |||
| 135 | // Change the context for the click callback to be the main element |
||
| 136 | click = props.click; |
||
| 137 | buttonOptions = { |
||
| 138 | icon: props.icon, |
||
| 139 | iconPosition: props.iconPosition, |
||
| 140 | label: props.text |
||
| 141 | }; |
||
| 142 | |||
| 143 | delete props.click; |
||
| 144 | delete props.icon; |
||
| 145 | delete props.iconPosition; |
||
| 146 | delete props.text; |
||
| 147 | |||
| 148 | $('<button></button>', props) |
||
| 149 | .button(buttonOptions) |
||
| 150 | .appendTo(buttonset) |
||
| 151 | .on('click', function() { |
||
| 152 | click.apply(dialog[0], arguments); |
||
| 153 | }); |
||
| 154 | }); |
||
| 155 | |||
| 156 | dialog.find('> .fa-spinner').hide(); |
||
| 157 | dialog.find('> iframe').css('visibility', 'visible'); |
||
| 158 | } else { |
||
| 159 | $('.midcom-view-toolbar').show(); |
||
| 160 | } |
||
| 161 | }); |
||
| 162 |